Page({
  data:{
    password:{}
  },
  onload(options){
    if(options.id) this.getPassport(options.id)
    if(options.encryptedData) this.getPassportShare(options.encryptedData)
    this.getPassport(options.id)
  },
  //获取通行证信息
  async getPasspory(id){
    let res = await wx.http.get('/repair/'+id)
    console.log(res);
    this.setData({passport:res})
  },
  // 获取分享界面信息
  async getPassportShare(encryptedData){
    let res = await wx.http.get('/visitor/share/'+ encryptedData)
    this.setData({passport:res})
  },
  // 保存二维码
  saveQRCode(){
    // 1.读取图片信息
    wx.getImageInfo({
      src: this.data.passport.url,
      success:(result)=>{
        console.log(result);
        // 调用api保存图片到相册
        wx.saveImageToPhotosAlbum({
          filePath:result.path,
          success:(res)=>{
            console.log(res);
          },
          fail:(error)=>{
            console.log(error);
          }
        })
      },
      fail:(err)=>{
        console.log(err)
      }
    })
  },
  onShareAppMessage() {
    return {
      title: '查看通行证',
      path: '/visitor_pkg/pages/passport/index?encryptedData=' + this.data.passport.encryptedData,
      imageUrl: 'https://enjoy-plus.oss-cn-beijing.aliyuncs.com/images/share_poster.png',
    }
  },
})
